import {
  Controller,
  Get,
  Param,
  Delete,
  Query,
  Body,
  Req,
  Post,
} from '@nestjs/common';
import { UserService } from './user.service';
import { Public } from 'src/common/decorators/public.decorator';
import { ApiProperty, ApiQuery } from '@nestjs/swagger';

@Controller('user_web')
export class UserController {
  constructor(private readonly userService: UserService) {}

  // @Post()
  // create(@Body() createUserDto: CreateUserDto) {
  //   return this.userService.create(createUserDto);
  // }

  @Get('/get_user_info')
  @ApiProperty({
    description: '通过token获取用户信息',
  })
  async getUserInfo(@Req() request: any) {
    return await this.userService.findOneUser(request.managerInfo.sub);
  }

  @Get('/get_car_info')
  @ApiProperty({
    description: '通过token获取用户信息',
  })
  getCarInfo(@Req() request) {
    const userId = request.managerInfo.sub;

    return this.userService.getCarInfo(userId);
  }

  @Post('/became_shop')
  becomeShop(@Req() request: any, @Body() params) {
    const userId = request.managerInfo.sub;
    return this.userService.becomeShop(userId, params);
  }

  @Post('/update_user')
  async upDateUser(@Req() request: any, @Body() params) {
    const userId = request.managerInfo.sub;
    return await this.userService.upDateUser(userId, params);
  }

  @Get('/shop_list')
  getShopList(@Req() request: any) {
    const userId = request.managerInfo.sub;
    return this.userService.findShopList(userId);
  }

  // 获取发布过的服务
  @Get('/service_publish')
  @ApiQuery({ name: 'keywords', description: '关键词', required: true })
  getServicesList(@Req() request: any, @Query('keywords') keywords) {
    const userId = request.managerInfo.sub;
    return this.userService.getServicesList(userId, keywords);
  }

  // 新增店铺
  @Post('add_shop')
  addShop(@Req() req, @Body() params) {
    const userId = req.managerInfo.sub;
    return this.userService.addShop(userId, params);
  }

  // @Get()
  // findAll() {
  //   return this.userService.findAll();
  // }

  // @Patch(':id')
  // update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
  //   return this.userService.update(+id, updateUserDto);
  // }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }
}
